package com.molyfun.parents.activity.organization.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.molyfun.parents.R;
import com.molyfun.parents.rest.bean.SignUpDetailEvaluateBean;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 *
 */
public class SignUpEvaluateAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    Context mContext;
    private List<SignUpDetailEvaluateBean.DataBean.RecordsBean>  mList;
//    private int mCurrentCategory = StoreTopBar.StoreBarChooseTab.BAR_USING;

    private SignUpEvaluateViewHolder mSignUpEvaluateViewHolder;
    private int mSelectorPosition = -1;


    public SignUpEvaluateAdapter(Context context) {
        this.mContext = context;
    }

    public SignUpEvaluateAdapter(Context context, int category) {
        this.mContext = context;
//        this.mCurrentCategory = category;
    }

    public void refreshData(List<SignUpDetailEvaluateBean.DataBean.RecordsBean> records) {
        this.mList = records;
        notifyDataSetChanged();
    }


    public void clearAll() {
        if (mList != null) {
            mList.clear();
            notifyDataSetChanged();
        }
    }

    public void addAll(List<SignUpDetailEvaluateBean.DataBean.RecordsBean>  list) {
        this.mList.addAll(list);
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new SignUpEvaluateViewHolder(LayoutInflater.from(parent.getContext())
                .inflate(R.layout.layout_sign_up_evaluate, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        SignUpDetailEvaluateBean.DataBean.RecordsBean recordsBean = mList.get(position);
        mSignUpEvaluateViewHolder = (SignUpEvaluateViewHolder) holder;
        mSignUpEvaluateViewHolder.mChoiceQuestion.setText(recordsBean.getContent());

        mSignUpEvaluateViewHolder.mAnswerContainer.removeAllViews();
        int optionNum = 0;
        for(SignUpDetailEvaluateBean.DataBean.RecordsBean.OptionBean optionBean : recordsBean.getOption()) {
            View view = LayoutInflater.from(mContext).inflate(R.layout.view_include_choose_info, null, false);
            final ImageView questionState = (ImageView) view.findViewById(R.id.question_check_state);
            TextView questionText = (TextView) view.findViewById(R.id.question_text);
            questionText.setText(optionBean.getContent());
            mSignUpEvaluateViewHolder.mAnswerContainer.addView(view);
            if(recordsBean.getOption().get(optionNum).getIsselected().equals("1")) {
                questionState.setImageResource(R.mipmap.ic_pay_checkbox_choosed);
            }else {
                questionState.setImageResource(R.mipmap.ic_pay_checkbox_normal);
            }
            optionNum ++;

        }
    }

    public class SignUpEvaluateViewHolder extends RecyclerView.ViewHolder {

        @InjectView(R.id.choice_question)
        public TextView mChoiceQuestion;
        @InjectView(R.id.answer_container)
        LinearLayout mAnswerContainer;

        public SignUpEvaluateViewHolder(View view) {
            super(view);
            ButterKnife.inject(this, view);
        }
    }

    @Override
    public int getItemCount() {
        if (mList == null || mList.size() == 0) {
            return 0;
        }
        return mList.size();
    }

}
